package com.db.mapper;

import com.db.pojo.Picture;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
import java.util.Map;

import static com.graduate.utils.ConstantConfig.PICTURE_BANNER;
import static com.graduate.utils.ConstantConfig.PICTURE_CONTENT;
import static com.graduate.utils.ConstantConfig.STATE_NO_DELETE;

@Mapper
public interface PictureMapper {
    //查询首页轮播图
    @Select("SELECT * FROM picture WHERE state='" + STATE_NO_DELETE + "' AND type='" + PICTURE_BANNER +
            "' ORDER BY createtime DESC LIMIT #{limit} OFFSET #{offset}")
    List<Map<String, Object>> getBanner(@Param("limit") String limit,@Param("offset") String offset);

    //查询吐槽模块内容图
    @Select("SELECT * FROM picture WHERE state='" + STATE_NO_DELETE + "' AND type='" + PICTURE_CONTENT +
            "' AND relative=#{relative} ORDER BY createtime DESC")
    List<Map<String, Object>> getLatelyPic(@Param("relative") String relative);

    //修改图片状态
    @Update("UPDATE picture SET status=#{status} WHERE id IN (#{ids})")
    int updatePicStatus(@Param("stauts") String status, @Param("ids") String id);

    @Select("SELECT content FROM picture WHERE id IN (#{ids})")
    List<Object> getContent(@Param("ids") String ids);

    @Select("SELECT * FROM picture WHERE id =#{id}")
    Picture getPictureById(@Param("id") String id);
}
